//package com.gx.util.fileutil;
//
//import com.alibaba.fastjson.JSON;
//import com.xinbang.usercenter.server.util.httpclientutil.HttpClientUtil;
//import com.xinbang.usercenter.server.util.httpclientutil.common.HttpConfig;
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//import moxie.cloud.service.common.exception.ServerException;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.ResponseEntity;
//import org.springframework.stereotype.Service;
//import org.springframework.util.FileCopyUtils;
//import org.springframework.web.client.RestTemplate;
//
//import java.io.ByteArrayInputStream;
//import java.io.InputStream;
//import java.net.URL;
//import java.util.Date;
//
///**
// * @author gaoxing
// * @create 2018-04-10 上午10:23
// */
//@Slf4j
//@Service
//public class SeaWeedfsServer implements FileUploadServer {
//    @Value("${seaweed.filerUrl}")
//    private String filterUrl;
//    @Autowired(required = false)
//    private RestTemplate restTemplate;
//
//    @Override
//    public void storeFile(String key, InputStream input) {
//        if (key.startsWith("/")) {
//            log.error("upload to seaweed exception:{}", "文件名不能以/ 开头 ");
////            putObjectResult.setResult(false);
////            putObjectResult.setMessage("上传seaweeddfs失败,"+"文件名不能以/ 开头");
////            return putObjectResult;
//            throw new RuntimeException();
//        }
//        String url = filterUrl + key;
//
//
//        try {
////            LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
////            ByteArrayResource arrayResource = new ByteArrayResource(FileCopyUtils.copyToByteArray(input)) {
////                @Override
////                public String getFilename() throws IllegalStateException {
////                    return key;
////                }
////
////            };
////            map.add("filename", arrayResource);
////            HttpHeaders headers = new HttpHeaders();
////            headers.setContentType(MediaType.MULTIPART_FORM_DATA);
////            HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
////                    map, headers);
////            ResponseEntity<String> result = restTemplate.exchange(
////                    url, HttpMethod.POST, requestEntity,
////                    String.class);
//            HttpConfig config = HttpConfig.custom().url(url).files(key, new ByteArrayInputStream(FileCopyUtils.copyToByteArray(input)));
//
//            SeaWeedDTO seaWeedDTO = JSON.parseObject(HttpClientUtil.upload(config), SeaWeedDTO.class);
//            if (StringUtils.isNotBlank(seaWeedDTO.getError())) {
//                log.error("upload to seaweed exception:{}", seaWeedDTO.getError());
//            }
//            log.info("文件上传成功 sedweed{}", seaWeedDTO);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }
//
//
//    @Override
//    public InputStream getFile(String key, boolean... ignoreException) {
//        try {
//            String url = filterUrl + key;
//
//            HttpHeaders headers = new HttpHeaders();
////            String url = template.getFileUrl(fid);
//            ResponseEntity<byte[]> response = restTemplate.exchange(
//                    url,
//                    HttpMethod.GET,
//                    new HttpEntity<byte[]>(headers),
//                    byte[].class);
//            return new ByteArrayInputStream(response.getBody());
//        } catch (Exception e) {
//            log.error("get seaweed file exception,:{}",e.getMessage(),e);
//        }
//        return null;
//    }
//
//    @Override
//    public URL generatePresignedUrl(String key, Date expiredTime) {
//        return null;
//    }
//
//    @Data
//    public static class SeaWeedDTO {
//
//
//        /**
//         * name : abc
//         * size : 22360
//         * fid : 2,044a5254c9
//         * url : http://127.0.0.1:8080/2,044a5254c9
//         */
//
//        private String name;
//        private int size;
//        private String fid;
//        private String url;
//        private String error;
//
//    }
//
//}
//
